package com.asset.salesforce.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import com.asset.salesforce.domain.Invoice;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

@Repository
public class InvoiceDaoImpl extends BasicDaoImpl<Invoice> {
	
	@SuppressWarnings("unchecked")
	public List<Invoice> getInvoicesEmployeeId(Integer empId) {
		
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from Invoice where  owner.id = :empId");
		query.setParameter("empId", empId);
		List<Invoice> invoices = new ArrayList<Invoice>();
		invoices = query.list();
		return invoices;
		
	}
public Invoice getInvoiceByEmployeeId(Integer empId) {
		
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from Invoice where  owner.id = :empId");
		query.setParameter("empId", empId);
		List<Invoice> invoices = new ArrayList<Invoice>();
		invoices = query.list();
		return invoices.get(0);
		
	}
	public Invoice getInvoice(Integer id){
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from Invoice where id = :id");
		query.setParameter("id", id);
		List<Invoice> invoices = new ArrayList<Invoice>();
		invoices = query.list();
		return invoices.get(0);
	}
}
